package com.talos.framework.common.util.date;

import java.time.Duration;
import java.time.LocalDateTime;

public class TimeStrUtils {

    public static String format(LocalDateTime date){

        String timeStr="";
        LocalDateTime now = LocalDateTime.now();
        Duration duration = Duration.between(now,date);
        if(duration.toMinutes()<=1){
            timeStr="刚刚";
        }else if(duration.toMinutes()<60 && duration.toMinutes()>1){
            timeStr= duration.toMinutes()+"分钟前";
        }else if(duration.toHours()<24 && duration.toHours()>=1){

            timeStr= duration.toHours()+"小时前";

        }else{
            timeStr= duration.toDays() +"天前";
        }
        return timeStr;

    }


    public static String format(LocalDateTime startTime, LocalDateTime endTime){

        String timeStr="";

        Duration duration = Duration.between(startTime,endTime);

        long timeDiff = duration.toMinutes();

        if(timeDiff<60){
            timeStr=timeDiff+"分钟";
        }else if(timeDiff<60*24 && timeDiff>=60){

            timeStr= timeDiff/60+"小时"+timeDiff%60+"分钟";

        }
        return timeStr;

    }
}
